﻿using AutoMapper;
using MediatR;
using SheepStorage.API.Application.Command.UserInfoCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.UserInfoHandlers
{
    /// <summary>
    /// 查看用户信息中介者
    /// </summary>
    public class UserInfoCreateHandlers : IRequestHandler<UserInfoCreateCommand, Results<int>>
    {
        private readonly IUserInfoService userInfoService;
        private readonly IMapper mapper;

        public UserInfoCreateHandlers(IUserInfoService userInfoService, IMapper mapper)
        {
            this.userInfoService = userInfoService;
            this.mapper = mapper;
        }


        public async Task<Results<int>> Handle(UserInfoCreateCommand request, CancellationToken cancellationToken)
        {

            var entity= mapper.Map<UserInfo>(request);

              var res= await   userInfoService.AddUserInfo(entity);
            return   Results<int>.DataResult(res);


          
        }
    }
}
